package com.dangdang.util;

import java.util.UUID;

public class VerifyCodeUtils {
	public static String generateCode(Integer id) {
		if (id == null)
			return null;
		UUID uuid = UUID.randomUUID();
		String code = uuid.toString() + "_" + id;
		return code;
	}

	public static String getCode(String input) {
		if (input == null)
			return null;
		if (input.lastIndexOf("_") < 0)
			return null;
		return input.substring(0, input.lastIndexOf("_"));
	}

	public static Integer getId(String input) {
		if (input == null)
			return null;
		if (input.lastIndexOf("_") < 0)
			return null;
		return Integer.valueOf(input.substring(input.lastIndexOf("_") + 1));
	}
}
